const formatTime = date =>{
	const year = date.getFullYear();
	const month = date.getMonth()+1;
	const day = date.getDate();
	const hour = date.getHours();
	const minute = date.getMinutes();
	const second = date. getSeconds();
	return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" +second;
}

function remove(arr,pos){
	arr[pos] = arr[arr.length - 1]
	arr.pop()
}

/**检查某字段的长度是否满足要求
 * @param {Object} field 要检查的字段变量
 * @param {Number} len 变量最小长度
 * @param {String} name 该字段的中文名称
 */
function checkLength(field, len, name){
	if(field.length >= len){
		return true
	}
	let message = name + "不能少于" + len + "个字符"
	if(field.length == 0){
		message = name + "不能为空"
	}
	uni.showToast({
		title: message,
		icon:"none"
	});
	return false
}

/**
 * 截取字符超过指定长度的部分，使用...省略
 * @param {String} str
 * @param {Int} len
 */
function ellipsis(str, len){
	if(str && str.length > len){
		return str.substr(0, len - 3) + "..."
	}
	return str
}

module.exports = {
	formatTime,
	remove,
	checkLength,
	ellipsis
}